package com.goodjob.musicplayer.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.goodjob.musicplayer.R;

public class PersonActivity extends AppCompatActivity {
    private static final String SHARED_PREFERENCES_NAME = "music_player";
    private ImageView returnImg;
    private TextView username_Text;
    private TextView userNick_Text;
    private TextView userPhone_Text;
    private TextView userEmail_Text;
    private Button aboutBtn;
    private Button editPersonBtn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.acitviy_person);
        returnImg = (ImageView) findViewById(R.id.img_return);
        aboutBtn = (Button) findViewById(R.id.btn_about);
        editPersonBtn = (Button) findViewById(R.id.btn_modifyPerson);
        userEmail_Text = (TextView) findViewById(R.id.text_userEmail);
        username_Text = (TextView) findViewById(R.id.text_username);
        userNick_Text = (TextView) findViewById(R.id.text_userNick);
        userPhone_Text = (TextView) findViewById(R.id.text_userPhone);
        initView();
        returnImg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(PersonActivity.this,ListActivity.class);
                startActivity(intent);
                finish();
            }
        });
        editPersonBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(PersonActivity.this,EditActivity.class);
                startActivity(intent);
                finish();
            }
        });
        aboutBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(PersonActivity.this,AboutActivity.class);
                startActivity(intent);
                finish();
            }
        });

    }

    void initView(){
        SharedPreferences sharedPreferences = getSharedPreferences("is", MODE_PRIVATE);
        try{
            username_Text.setText(sharedPreferences.getString("name",""));

            if (sharedPreferences.getString("phone", "").equals("")){
                userPhone_Text.setText("暂未设置");
            }else{
                userPhone_Text.setText(sharedPreferences.getString("phone", ""));
            }

            if (sharedPreferences.getString("nick", "").equals("")){
                userNick_Text.setText("暂未设置");
            }else{
                userNick_Text.setText(sharedPreferences.getString("nick",""));
            }

            if (sharedPreferences.getString("email", "").equals("")){
                userEmail_Text.setText("暂未设置");
            }else{
                userEmail_Text.setText(sharedPreferences.getString("email",""));
            }

        }catch (Exception e){

        }

    }
}
